﻿using System;
using UI;
using UnityEngine;

public class DetailInfo : MonoBehaviour
{
    public GameObject uiPrefab;

    [Header("前置条件")]
    public NeedItemInfo[] needInfoArr;
    [Header("隐藏条件")]
    public HideInfo hideInfo;
    
    [Header("触发剧本")]
    public string triggerScenario;

    private bool m_registed;
    private void OnEnable()
    {
        if (hideInfo.Check()) gameObject.SetActive(false);
        else if (hideInfo.Valid())
        {
            m_registed = true;
            InventoryManager.OnGetItem += OnGetItem;
            InventoryManager.OnUseItem += OnUseItem;
        }
    }
    private void OnDisable()
    {
        if (m_registed)
        {
            m_registed = false;
            InventoryManager.OnGetItem -= OnGetItem;
            InventoryManager.OnUseItem -= OnUseItem;
        }
    }
    
    //回调
    private void OnGetItem(EItemType type)
    {
        if (hideInfo.Check())
        {
            gameObject.SetActive(false);
        }
    }
    private void OnUseItem(EItemType type)
    {
        if (hideInfo.Check())
        {
            gameObject.SetActive(false);
        }
    }
}